<%
    Users user = Trader.getUser(request.getParameter("uid"));
	wstrader.task.trade.reports.PriceFixed task = user.trade.reports.price_fixed;

	task.getRequest().setRequest(request);
	task.getResponse().setResponse(response,out);
	
	if (!user.Authenticated()) {
		response.sendRedirect("logon.jsp");
		return;
	}
	((Tasks)task.getOwner()).clearFocus();
	task.setFocus(true);
		
	long focused_id = task.doTask();
		
	Trader.window_width = "90%";
		
	ResultSet Rs = task.fetchUnfixedContract();
%>

<%@include file="../header.jsp"%><style type="text/css">
<!--
.style1 {
	font-family: Arial;
	font-size: 18px;
}
.style4 {
	font-family: Arial;
	font-size: 12px;
}
.style3 {font-weight: bold}
-->
</style>

<script language="javascript">
function doFilter()
{
	var form = document.formMain;
	form.action = "trade.reports.price-fixed.jsp";
	form.submit();
}

function ViewReport()
{
	var form = document.formMain;
	if (form.terminal_market.value!="")
	{
		if (form.type.value !="")
		{	
			form.submit();
		}
		else
		{
			alert("Please select the Parameter value for market type");
		}
	}
	else
	{
		alert("Please select the Parameter value for terminal month");
	}
		
}
function doReport()
{
	var form = document.formMain;
	//if (form.terminal_market.value!="")
	//{
		//if (form.type.value !="")
		//{
			doTask(5);
		//}
		//else
		//{
			//alert("Please select the Parameter value for market type");
		//}
	//}
	//else
	//{
		//alert("Please select the Parameter value for terminal month");
	//}
}

function changeMrkMth()
{
        var terminal_market = getValue("terminal_market");
        var obj1 = getObj("terminal_month");
        obj1.options.length = 0;
        obj1.options[0] = new Option("All");
        obj1.options[0].value = "0";
        obj1.options[0].title = "";

        var date = new Date();
        var curMth = date.getMonth()+1;
        var Yrs = 2005//date.getYear()-1;
        var curYrs = current_year;
        numCurYrs = curYrs;
        strCurYrs = numCurYrs.toString();

        var curYrs = strCurYrs.substring(2);
        var loop = 1
        var strMth = "";
        if (terminal_market == "NYC")
        {
                while (loop <= 20)
                {
                        if ((curMth >= 1) && (curMth <= 3))
                        {
                                strMth = "Mar-"+curYrs;
                                curMth = 3;
                        }

                        if ((curMth >= 4) && (curMth <= 5))
                        {
                                strMth = "May-"+curYrs;
                                curMth = 5;
                        }

                        if ((curMth >= 6) && (curMth <= 7))
                        {
                                strMth = "Jul-"+curYrs;
                                curMth = 7;
                        }

                        if ((curMth >= 8) && (curMth <= 9))
                        {
                                strMth = "Sep-"+curYrs;
                                curMth = 9;
                        }

                        if ((curMth >= 10) && (curMth <= 12))
                        {
                                strMth = "Dec-"+curYrs;
                                curMth = 12;
                        }

                        obj1.options[loop] = new Option(strMth);
                        obj1.options[loop].value = "01-" + strMth;
                        obj1.options[loop].title = strMth;

                        if (curMth <= 9)
                        {
                                curMth = curMth+2;
                        }
                        else
                                if (curMth == 9)
                                {
                                        curMth = curMth+3;
                                }
                                else
                                        if (curMth == 12)
                                        {
                                                curMth = 3;
                                                numCurYrs = numCurYrs+1;
                                                strCurYrs = numCurYrs.toString();
                                                curYrs = strCurYrs.substring(2);
                                        }
                        loop=loop+1;
                }

        }
        else
        {
                while (loop <= 24)
                {
                        if ((curMth >= 1) && (curMth <= 2))
                        {
                                strMth = "Jan-"+curYrs;
                                curMth = 1;
                        }

                        if ((curMth >= 3) && (curMth <= 4))
                        {
                                strMth = "Mar-"+curYrs;
                                curMth = 3;
                        }

                        if ((curMth >= 5) && (curMth <= 6))
                        {
                                strMth = "May-"+curYrs;
                                curMth = 5;
                        }

                        if ((curMth >= 7) && (curMth <= 8))
                        {
                                strMth = "Jul-"+curYrs;
                                curMth = 7;
                        }

                        if ((curMth >= 8) && (curMth <= 9))
                        {
                                strMth = "Sep-"+curYrs;
                                curMth = 9;
                        }

                        if ((curMth >= 10) && (curMth <= 11))
                        {
                                strMth = "Nov-"+curYrs;
                                curMth = 11;
                        }

                        obj1.options[loop] = new Option(strMth);
                        obj1.options[loop].value = "01-" + strMth;
                        obj1.options[loop].title = strMth;

                        if (curMth <= 9)
                        {
                                curMth = curMth+2;
                        }
                        else
                                if (curMth == 11)
                                {
                                        curMth = 1;
                                        numCurYrs = numCurYrs+1;
                                        strCurYrs = numCurYrs.toString();
                                        curYrs = strCurYrs.substring(2);
                                }
                        loop=loop+1;
                }
        }
}

function selectRow(row)
{
	var form = document.formMain;
	form.contracts.value=row.id;
	highlightonthis(row);
}
function openfixation(row)
{
	var form = document.formMain;
	form.view.value="1";
	form.action = "trade.fixation.jsp";
	form.submit();	
}

</script>
<form method="POST" name="formMain" action="" onSubmit="return dosearch()">				  
	<input type="hidden" name="uid"        id="uid"       value="<%=user.getuid()%>">
    <span class="style3">
    <input type="hidden" name="task_id"    id = "task_id"   value="0">
    <input name="view" type="hidden" id="view" value="0">
    <input name="contracts" type="hidden" id="contracts" value="0">
  </span>  
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="3"><strong><span class="style1"><img src="images/unfixed-report.jpg" width="250" height="30"></span></strong></td>
        <td width="27%">&nbsp;</td>
        <td width="8%">&nbsp;</td>
        <td width="6%">&nbsp;</td>
        <td width="7%">&nbsp;</td>
        <td width="6%">&nbsp;</td>
        <td width="6%">&nbsp;</td>
        <td width="4%">&nbsp;</td>
      </tr>
      <tr>
	  
        <td colspan="10">
	    <table>
    <tr>
      <td width="150" align="center" bgcolor="#EEEEEE"><strong><span class="style4">Buyer/Seller</span></strong></td>
      <td width="150" align="center" bgcolor="#EEEEEE"><strong><span class="style4">Market</span></strong></td>
      <td align="center" bgcolor="#EEEEEE"><strong><span class="style4">Month</span></strong></td>
      <td align="center" bgcolor="#EEEEEE"><strong></strong></td>
      <td align="center" bgcolor="#EEEEEE"><strong><span class="style4">Contract Type </span></strong></td>
    </tr>
    <tr>
      <td height="32"><select name="buyer_seller" size="9" id="select" onChange="doFilter()" style="font-family:Arial; font-size:11px; width:150px;border:0">
        <option value="0" selected>All</option>
        <%
			task.getResponse().setOption(task.getBuyerSellerList());
			task.getResponse().setSelected("buyer_seller");
		%>
      </select>
	  </td>
      <td><select name="terminal_market" size="9" id="terminal_market" onChange="doFilter()" style="font-family:Arial; font-size:11px; width:150px;border:0">
        <option value="0" selected>All</option>
        <option value="NYC">NYC</option>
        <option value="LIFFE">LIFFE</option>
        <%task.getResponse().setSelected("terminal_market");%>
      </select>
	  </td>
      <td>
        <select name="terminal_month" size="9" id="terminal_month" onChange="doFilter()" style="font-family:Arial; font-size:11px; width:150px;border:0">
           <script>
		  		changeMrkMth();
		   </script>
		   <%
		   task.getResponse().setSelected("terminal_month");
		   %>
        </select>
</td>
      <td>&nbsp;
	  </td>
      <td><select name="cnt_type" size="9" id="cnt_type" onChange="doFilter()" style="font-family:Arial; font-size:11px; width:150px;border:0">
        <option value="0" selected>All</option>
        <option value="P">PURCHASE</option>
        <option value="S">SALES</option>
        <%task.getResponse().setSelected("cnt_type");%>
      </select>
	  </td>
    </tr>
	  
	  </table>		
		</td>
		
      </tr>
      <tr>
        <td colspan="10"><table width="100%"  border="1" cellspacing="0" cellpadding="0">
          <tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
            <td width="1%" align="center">&nbsp;</td>
            <td width="1%" align="center">&nbsp;</td>
            <td width="1%" align="center">&nbsp;</td>
            <td width="15%" height="30" align="center"><strong><span class="style4">Ref.No.</span></strong></td>
            <td width="3%" align="center"><strong><span class="style4">Buyer No. </span></strong></td>
            <td width="16%" align="center"><strong><span class="style4">Buyer</span></strong></td>
            <td width="29%" align="center"><strong><span class="style4">Grade</span></strong></td>
            <td width="8%" align="center"><strong><span class="style4">Price</span></strong></td>
            <td width="6%" align="center"><strong><span class="style4">Diff</span></strong></td>
            <td width="8%" align="center"><strong><span class="style4">Ship Date </span></strong></td>
            <td width="6%" align="center"><strong><span class="style4">Fixed</span></strong></td>
            <td width="6%" align="center"><strong><span class="style4">Unfixed</span></strong></td>
          </tr>
          <%
	  	String Mrk = "";
		String RecMrk = "";
		String OldMrk = "T";
		
		String CType = "";
		String RecCType = "";
		
		String TMth = "";
		String RecTMth = "";
		
		String CntType = "";
		
		float GTot_Fix=0;
		float GTot_UnFix=0;
		
		float PTerTot_Fix=0;
		float PTerTot_UnFix=0;
		float STerTot_Fix=0;
		float STerTot_UnFix=0;
		String TotName = "";
		
		int loop = 0;
	  	if (Rs.first() ==true)
		{
			Rs.beforeFirst();
	  		while (Rs.next())
			{
				RecMrk = Rs.getString("terminal_market");
				RecCType = Rs.getString("type");

				if (RecCType.compareTo("P")==0) CntType = "Purchase";
				if (RecCType.compareTo("S")==0) CntType = "Sales";						
				if (Rs.getDate("terminal_month") != null)
				{
					RecTMth = Utils.dateToStr(Rs.getDate("terminal_month")).substring(3);
				}
				else
				{
					RecTMth = "";
				}

//---------------------------------------------------------------------------------------------------------------------------------------				
				
				if (Mrk.compareTo(RecMrk) != 0)
				{
					Mrk = RecMrk;
					if (Mrk.compareTo("NYC")==0)
					{
	 %>
          				<tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
						<td align="Left"><strong><span class="style4"></span></strong></td>		 
						<td align="Left"><strong><span class="style4"></span></strong></td>		 					  
            			<td align="Left" colspan="8"><strong><span class="style4">Total  <%=TotName%></span></strong></td>
						<%
							GTot_Fix = PTerTot_Fix + STerTot_Fix;
							GTot_UnFix = PTerTot_UnFix + STerTot_UnFix;
						%>
            			<td align="right"><strong><span class="style4"><%=Utils.numberToStr(GTot_Fix,3,false)%></span></strong></td>
            			<td align="right"><strong><span class="style4"><%=Utils.numberToStr(GTot_UnFix,3,false)%></span></strong></td>
          				</tr>
     <%
						GTot_Fix = 0;
						GTot_UnFix = 0;
						PTerTot_Fix = 0;
						STerTot_Fix = 0;
						PTerTot_UnFix = 0;
						STerTot_UnFix = 0;		 
	 				}
	 %>								
	 
          <tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
		    <td colspan="12" align="Left"><strong><span class="style4">Contracts Against :- <%=RecMrk%></span></strong></td>
          </tr>
     <%			
	 				OldMrk = "C";
				}				
//---------------------------------------------------------------------------------------------------------------------------------------				
				if (TMth.compareTo(RecTMth) != 0)
				{

					TMth = RecTMth;
					if (OldMrk.compareTo("T")==0)
					{
					
	 %>
          				<tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
						<td align="Left"><strong><span class="style4"></span></strong></td>		 
						<td align="Left"><strong><span class="style4"></span></strong></td>		 					  
            			<td align="Left" colspan="8"><strong><span class="style4">Total  <%=TotName%></span></strong></td>
						<%
							GTot_Fix = PTerTot_Fix + STerTot_Fix;
							GTot_UnFix = PTerTot_UnFix + STerTot_UnFix;
						%>
            			<td align="right"><strong><span class="style4"><%=Utils.numberToStr(GTot_Fix,3,false)%></span></strong></td>
            			<td align="right"><strong><span class="style4"><%=Utils.numberToStr(GTot_UnFix,3,false)%></span></strong></td>
          				</tr>		
				
	 <%	
	   			    }
					else
					{
						OldMrk="T";
					}
							
					if (CType.compareTo(RecCType) != 0)
					{
	 %>
          				<tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
						<td align="Left"><strong><span class="style4"></span></strong></td>		  
            			<td colspan="11" align="Left"><strong><span class="style4"><%=RecTMth%></span></strong></td>
          				</tr>
	 <%
					}
					else
					{
	 %>
          				<tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
						<td align="Left"><strong><span class="style4"></span></strong></td>		  
            			<td colspan="11" align="Left"><strong><span class="style4"><%=RecTMth%></span></strong></td>
          				</tr>	 
          				<tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
						<td align="Left"><strong><span class="style4"></span></strong></td>		 
						<td align="Left"><strong><span class="style4"></span></strong></td>		 					  
            			<td colspan="10" align="Left"><strong><span class="style4"><%=CntType%></span></strong></td>
          				</tr>	 
     <%			
					}	 
//		  			CType = RecCType;
//					TotName = CntType;

					GTot_Fix = 0;
					GTot_UnFix = 0;
					PTerTot_Fix = 0;
					STerTot_Fix = 0;
					PTerTot_UnFix = 0;
					STerTot_UnFix = 0;					
				}
//-------------------------------------------------------------------------------------------------------------------------------								
				if (CType.compareTo(RecCType) != 0)
				{
					if (CType.compareTo("P")==0)
					{
	 %>
          				<tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
						<td align="Left"><strong><span class="style4"></span></strong></td>		 
						<td align="Left"><strong><span class="style4"></span></strong></td>		 					  
            			<td align="Left" colspan="8"><strong><span class="style4">Total  <%=TotName%></span></strong></td>
						<%
							GTot_Fix = PTerTot_Fix + STerTot_Fix;
							GTot_UnFix = PTerTot_UnFix + STerTot_UnFix;
						%>
            			<td align="right"><strong><span class="style4"><%=Utils.numberToStr(GTot_Fix,3,false)%></span></strong></td>
            			<td align="right"><strong><span class="style4"><%=Utils.numberToStr(GTot_UnFix,3,false)%></span></strong></td>
          				</tr>		
	 <%
					}
	 %> 
          			<tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
					<td align="Left"><strong><span class="style4"></span></strong></td>		 
					<td align="Left"><strong><span class="style4"></span></strong></td>		 					  
            		<td colspan="10" align="Left"><strong><span class="style4"><%=CntType%></span></strong></td>
          			</tr>
      <%		

		  			CType = RecCType;
					TotName = CntType;
					GTot_Fix = 0;
					GTot_UnFix = 0;
					PTerTot_Fix = 0;
					STerTot_Fix = 0;
					PTerTot_UnFix = 0;
					STerTot_UnFix = 0;
				}			
//--------------------------------------------------------------------------------------------------------------------------------					
	  %>
          <tr id=<%=Rs.getInt("id")%> bordercolor="#EEEEEE" onClick="selectRow(this);">
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
            <td height="20" align="center"><span class="style4"><a href="javascript:openfixation(this);"><%=Rs.getString("ref_number")%></a></span></td>
            <%
							String Ref ="";
							if (Rs.getString("supplier_buyer_ref") == null)
							{
								Ref = "-";
							}
							else
							{
								if (Rs.getString("supplier_buyer_ref").compareTo("")==0)
								{
									Ref = "-";
								}
								else
								{
									Ref = Rs.getString("supplier_buyer_ref");
								}
							}	

					%>
            <td align="center"><span class="style4"><%=Ref%></span></td>
            <td><span class="style4"><%=task.getFieldValueForId("company_master","name",Rs.getInt("supplier_buyer_id"))%></span></td>
            <td><span class="style4"><%=task.getFieldValueForId("grade_master","name",Rs.getInt("grade_id"))%></span></td>
            <td align="right"><span class="style4"><%=Utils.numberToStr(Rs.getFloat("contract_price_foreign"),2,false)%></span></td>
            <td align="right"><span class="style4"><%=Utils.numberToStr(Rs.getFloat("differential"),2,false)%></span></td>
            <td align="center"><span class="style4"><%=Utils.dateToStr(Rs.getDate("last_date")).substring(3)%></span></td>
            <td align="right"><span class="style4"><%=Utils.numberToStr(Rs.getFloat("fixed_tons"),3,false)%></span></td>
            <td align="right"><span class="style4"><%=Utils.numberToStr(Rs.getFloat("unfixed_tons"),3,false)%></span></td>
			<%
				if (CType.compareTo("P")==0) PTerTot_Fix = PTerTot_Fix + Rs.getFloat("fixed_tons");
				if (CType.compareTo("S")==0) STerTot_Fix = STerTot_Fix + Rs.getFloat("fixed_tons");
				if (CType.compareTo("P")==0) PTerTot_UnFix = PTerTot_UnFix + Rs.getFloat("unfixed_tons");
				if (CType.compareTo("S")==0) STerTot_UnFix = STerTot_UnFix + Rs.getFloat("unfixed_tons");
			%>
          </tr>
		  
          <%
	  		}
			
		  %>
		
          				<tr bordercolor="#EEEEEE" bgcolor="#DDDDDD">
						<td align="Left"><strong><span class="style4"></span></strong></td>		 
						<td align="Left"><strong><span class="style4"></span></strong></td>		 					  
            			<td align="Left" colspan="8"><strong><span class="style4">Total  <%=TotName%></span></strong></td>
						<%
							GTot_Fix = PTerTot_Fix + STerTot_Fix;
							GTot_UnFix = PTerTot_UnFix + STerTot_UnFix;
						%>
            			<td align="right"><strong><span class="style4"><%=Utils.numberToStr(GTot_Fix,3,false)%></span></strong></td>
            			<td align="right"><strong><span class="style4"><%=Utils.numberToStr(GTot_UnFix,3,false)%></span></strong></td>
          				</tr>			  
			
		 <%
		}
		else
		{
	  %>
          <tr bordercolor="#EEEEEE">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td height="21">&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td width="0%">&nbsp;</td>
          </tr>
          <%
	  	}
	  %>
        </table></td>
      </tr>
      <tr>
        <td width="10%" align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td width="10%" align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td width="16%" align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
  
      <tr>
        <td><span class="style3">
        </span></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><img src="images/report.jpg" width="55" height="18" onClick="doReport();"></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
</form>


<%@include file="../footer.jsp"%>

